<?php

/*
 * Login Class
 * 
 * Performs basic authentication
 * 
 * @author : Jason Meulenhoff
 * @mail : mail@kacangboi.com
 * @web : http://kacangboi.com
 * @copyright : KacangNetworks 2010
 * 
 */

class login
{
	private $query;
	
	public function __construct()
	{
		$this->query = new databaseManager();	
	}
	
	public function login($user,$pass)
	{
		if($user == "Administrator" || $user == "administrator" && $this->query->Adminlogin($user,$pass) && !empty($_SERVER['REMOTE_ADDR']))
		{
			$this->handleLogin($user);
			$_SESSION['admin'] = true;
			echo 100100200;
		}
		else if($this->query->login($user,$pass) && !empty($_SERVER['REMOTE_ADDR']))
		{
			$this->handleLogin($user);
			echo 100100100;
		}
		else
			echo "<img src='../images/error.png'/> Wrong Username / Password Combination";
	}
	public function handleLogin($user)
	{
		if(!$this->query->sessionExsists())
			$this->query->setSession($user);
		else
			$this->query->updateSession();
		/* Creating Session Files*/
		$_SESSION['logged'] = array("name" => $user,"ip" => $_SERVER['REMOTE_ADDR'],"valid" => $this->query->sessionActive());
	}
	public function logout()
	{
		session_destroy();
		$this->query->expireSession();
	}
}
?>